﻿// -----------------------------------------------------------------------
// <copyright file="TableParameters.cs" company="JSC Centido">
//  Copyright (c) JSC Centido. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace Centido.Core
{
    using System;

    /// <summary>
    ///   The auxiliary parameters used when creating a user-defined table.
    /// </summary>
    /// <remarks>This class is used when specifying the auxiliary table creation parameters
    /// such as system column ids, the need for default table indexes etc.</remarks>
    /// <example>
    ///   The following example shows how to create a table without default indexes.
    /// <code>
    ///     using System;
    ///     using Centido.Core;
    /// 
    ///     class DomainSample
    ///     {
    ///         static void Main()
    ///         {
    ///             var domainConfig = new DomainConfiguration()
    ///             {
    ///                 DbConnectionString = @"Driver={SQL Server};Server=.\SQLEXPRESS;Database=MyDb;Uid=admin;Pwd=P@ssw0rd;",
    ///                 DbProviderName = "MSSQLSERVER"
    ///             };
    ///         
    ///             var domain = Domain.Build(domainConfig);
    /// 
    ///             domain.DeleteAll();
    ///         
    ///             //Creating a table without default indexes
    ///             var table = domain.AddTable("my_table",
    ///                 new TableParameters() { DefaultIndexes = false });
    /// 
    ///             Console.WriteLine("Table index count = {0}", table.Indexes.Count());
    /// 
    ///             //Inserting two rows with the same id
    ///             var rowId = Guid.NewGuid();
    /// 
    ///             table.GrantAll();
    ///             table.InsertRow(rowId);
    ///             table.InsertRow(rowId);
    /// 
    ///             //Reading the inserted rows
    ///             domain.DbAccess.ExecuteReader(cmd =>
    ///             {
    ///                 cmd.CommandText = string.Format("select id from {0}", table.FullName); 
    ///             }, reader =>
    ///             {
    ///                 Console.WriteLine("Row id = {0}", reader.GetGuid("id"));
    ///             });
    ///         }
    ///     }
    /// </code>
    /// </example>
    public sealed class TableParameters
    {
        /// <summary>
        ///  Initializes a new instance of the <see cref="Centido.Core.TableParameters"/> class.
        /// </summary>
        public TableParameters()
        {
            IdColumnId = Guid.NewGuid();
            OwnerColumnId = Guid.NewGuid();
            CreatedByColumnId = Guid.NewGuid();
            CreatedOnColumnId = Guid.NewGuid();
            UpdatedByColumnId = Guid.NewGuid();
            UpdatedOnColumnId = Guid.NewGuid();
            DeletedByColumnId = Guid.NewGuid();
            DeletedOnColumnId = Guid.NewGuid();
            IsActiveColumnId = Guid.NewGuid();
            RowVersionColumnId = Guid.NewGuid();
            DefaultIndexes = true;
            IdColumnIndexId = Guid.NewGuid();
            IsActiveColumnId = Guid.NewGuid();
        }

        /// <summary>
        ///   Gets or sets the id of the table column that stores the row id.
        /// </summary>
        public Guid IdColumnId { get; set; }

        /// <summary>
        ///  Gets or sets the id of the table column that stores the row owner. 
        /// </summary>
        public Guid OwnerColumnId { get; set; }

        /// <summary>
        ///   Gets or sets the id of the table column that stores the name of the user who has created the row.
        /// </summary>
        public Guid CreatedByColumnId { get; set; }

        /// <summary>
        ///   Gets or sets the id of the table column that stores the row creation date and time.
        /// </summary>
        public Guid CreatedOnColumnId { get; set; }

        /// <summary>
        ///   Gets or sets the id of the table column that stores the name of the user who has updated the row last.
        /// </summary>
        public Guid UpdatedByColumnId { get; set; }

        /// <summary>
        ///   Gets or sets the id of the table column that stores the row last update date and time.
        /// </summary>
        public Guid UpdatedOnColumnId { get; set; }

        /// <summary>
        ///   Gets or sets the id of the table column that stores the name of the user who has deleted the row.
        /// </summary>
        public Guid DeletedByColumnId { get; set; }

        /// <summary>
        ///   Gets or sets the id of the table column that stores the row deletion date and time.
        /// </summary>
        public Guid DeletedOnColumnId { get; set; }

        /// <summary>
        ///   Gets or sets the id of the table column that stores the information about the row activity.
        /// </summary>
        public Guid IsActiveColumnId { get; set; }

        /// <summary>
        ///   Gets or sets the id of the table column that stores the row version.
        /// </summary>
        public Guid RowVersionColumnId { get; set; }

        /// <summary>
        ///   Gets or sets the need to create default table indexes.
        /// </summary>
        /// <value>True if there is a need to create default table indexes; otherwise, false.</value>
        public bool DefaultIndexes { get; set; }

        /// <summary>
        ///   Gets or sets the id of the default table index on the row id column.
        /// </summary>
        public Guid IdColumnIndexId { get; set; }

        /// <summary>
        ///   Gets or sets the id of the default index on the IsActive column.
        /// </summary>
        public Guid IsActiveIndexId { get; set; }
    }
}